package per.qiao.simplechian.bo;

import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: qiaoyp
 * @Date: 2024/8/21 18:58
 * @Description:
 */
@Getter
@Setter
public class NodeParam {

    /**
     * 业务参数
     */
    private Object param;

    /**
     * 链路执行过程中传递的参数, 生命周期在链路上
     */
    private Map<String, Object> extParam;

    private NodeParam(Object param) {
        this.param = param;
    }

    public static NodeParam of(Object param) {
        return new NodeParam(param);
    }

    public <T> T getParam() {
        return (T) param;
    }

    public Map<String, Object> getExtParam() {
        if (extParam == null) {
            this.extParam = new HashMap<>(16);
        }
        return this.extParam;
    }

    public Map<String, Object> setExtVal(String key, Object val) {
        Map<String, Object> extParam = this.getExtParam();
        extParam.put(key, val);
        return extParam;
    }

    public Object getExtVal(String key) {
        return this.getExtParam().get(key);
    }
}
